

import java.lang.*;
import java.io.*;

import java.util.*;
import static java.lang.Float.parseFloat;

public class Main
{public static void main(String[] args) {
    Entry_system();
}

    static Scanner input = new Scanner(System.in);

    public static void Entry_system() {
        Menu.Menu1();
        int c = input.nextInt();
        switch (c) {
            case 0:
                System.out.println("成功退出系统!");
                System.exit(0);
            case 1:
                User_enter();
                return;
            case 2:
                User_reg();
                return;
            default:
                System.out.println("您输入的序号错误，请重新输入!");
                Entry_system();
        }
    }
    public static void User_enter() {
        Menu.Login1();
        int c = input.nextInt();
        switch (c) {
            case 0 :
                System.out.println("成功退出系统!");
                System.exit(0);
            case 1 :
                System.out.print("请输入用户号码: ");
                String num = input.next();
                System.out.print("请输入用户名字: ");
                String company = input.next();

                if(Objects.equals(num, "admin")&&Objects.equals(company, "admin")){
                    while (true) {
                        Menu.Menu_admin();
                        c = input.nextInt();
                        new Admin();
                        switch (c) {
                            case 0:
                                System.out.println("成功退出系统!");
                                System.exit(0);
                            case 1:
                                Admin.inout();
                                break;
                            case 2:
                                Admin.search();
                                break;
                            case 3:
                                Admin.show();
                            break;
                            case 4:
                                Admin.calvoucher();
                            break;
                            case 5:
                                Admin.statistics();
                            break;
                            default:
                                System.out.println("您输入的序号错误，请重新输入!");
                        }
                    }
                }

                try {
                    BufferedReader in;
                    int t = 0;
                    String NUM ="";
                    String COMPANY ="";
                    String line;
                    while (true) {
                        in = new BufferedReader(
                                new InputStreamReader(
                                        new FileInputStream("login.txt")));
                        while ((line = in.readLine()) != null) {
                            String[] a1 = line.split(" ");
                            if (a1[0].equals(num)&&a1[1].equals(company)) {
                                t = 1;
                                COMPANY = a1[1];
                                NUM = a1[0];
                                break;
                            }
                        }
                        if (t == 0) {
                            System.out.println("您的号码或名字输入错误，请重新输入: ");
                            System.out.print("请输入用户号码: ");
                            num = input.next();
                            System.out.print("请输入用户名字: ");
                            company = input.next();
                        }else {
                            break;
                        }
                    }
                    Company company1 = new Company(NUM,COMPANY);
                    while (true){
                        Menu.Menu_Company();
                        c = input.nextInt();
                        switch (c) {
                            case 0:
                                System.out.println("成功退出系统!");
                                System.exit(0);
                            case 1:
                                company1.inout();
                                break;
                            case 2:
                                company1.search();
                                break;
                        }
                    }
                }catch (IOException e) {
                    e.printStackTrace();
                }
            case 2 :
                Entry_system();
        }
    }

    public static void User_reg(){
        Menu.Login2();
        int c = input.nextInt();
        switch (c) {
            case 0 :
                System.out.println("成功退出系统!");
                System.exit(0);
            case 1 :
                System.out.print("请输入用户号码: ");
                String num = input.next();
                System.out.print("请输入用户名字: ");
                String company = input.next();
                try{
                    PrintWriter out = new PrintWriter(
                            new BufferedWriter(
                                    new OutputStreamWriter(
                                            new FileOutputStream("login.txt",true))));
                    out.println(num+" "+company);
                    out.close();
                    System.out.println("注册成功!");
                }catch (IOException e) {
                    e.printStackTrace();
                }
            case 2 :
                Entry_system();
        }
    }
}

